package com.xijia.wuyouwallet.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.xijia.wuyouwallet.R;
import java.util.List;

/**
 * Created by Administrator on 2017/7/24 0024.
 */

public class MeVpAdapter extends PagerAdapter {
    private Context context;
    private List<Integer> bList;
    private View[]views;
    private onVpCallBack callBack;
    public MeVpAdapter(Context context,List<Integer>bList,onVpCallBack callBack)
    {
        this.context=context;
        this.bList=bList;
        this.callBack = callBack;
        views = new View[bList.size()];
    }
    @Override
    public int getCount() {
        return bList.size();
    }
    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view.equals(object);
    }
    @Override
    public Object instantiateItem(ViewGroup container, final int position) {
        if(views[position]==null)
        {
            views[position] = LayoutInflater.from(context).inflate(bList.get(position),null);
        }
        LinearLayout ll1 = (LinearLayout) views[position].findViewById(R.id.list_me_vp_ll1);
        LinearLayout ll2 = (LinearLayout) views[position].findViewById(R.id.list_me_vp_ll2);
        LinearLayout ll3 = (LinearLayout) views[position].findViewById(R.id.list_me_vp_ll3);
        LinearLayout ll4 = (LinearLayout) views[position].findViewById(R.id.list_me_vp_ll4);
        ll1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //Toast.makeText(context,"哈哈",Toast.LENGTH_SHORT).show();
                callBack.onVpClick(position,0);
            }
        });
        ll2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                callBack.onVpClick(position,1);
            }
        });
        ll3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                callBack.onVpClick(position,2);
            }
        });
        ll4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                callBack.onVpClick(position,3);
            }
        });
        container.addView(views[position]);
        return views[position];
    }
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    public interface onVpCallBack{

        public void onVpClick(int page,int position);

    }
}
